package tianrun.ziguan.api.calculate.config.dto.response;

import org.hibernate.validator.constraints.Length;
import org.springframework.beans.BeanUtils;
import tianrun.ziguan.api.calculate.config.entity.TCalAsset;

import javax.validation.constraints.NotNull;
import java.util.List;

public class AssetGroupTree {
    private Long id;
    private String assetName;
    @NotNull(message = "资产编号不能为空")
    @Length(max = 50,message = "资产编号太长,不能超过50")
    private String assetNum;
    @NotNull(message = "模板id不能为空")
    private Long templateId;

    private Boolean virtualFlag;

    private List<AssetGroupTree> children;

    public List<AssetGroupTree> getChildren() {
        return children;
    }

    public void setChildren(List<AssetGroupTree> children) {
        this.children = children;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getTemplateId() {
        return templateId;
    }

    public void setTemplateId(Long templateId) {
        this.templateId = templateId;
    }

    public String getAssetNum() {
        return assetNum;
    }

    public void setAssetNum(String assetNum) {
        this.assetNum = assetNum;
    }

    public String getAssetName() {
        return assetName;
    }

    public void setAssetName(String assetName) {
        this.assetName = assetName;
    }

    public Boolean getVirtualFlag() {
        return virtualFlag;
    }

    public void setVirtualFlag(Boolean virtualFlag) {
        this.virtualFlag = virtualFlag;
    }

    public static AssetGroupTree of(TCalAsset asset){
        AssetGroupTree assetGroupTree = new AssetGroupTree();
        BeanUtils.copyProperties(asset,assetGroupTree);
        return assetGroupTree;
    }
    public TCalAsset to(){
        TCalAsset asset = new TCalAsset();
        BeanUtils.copyProperties(this,asset);
        //保存资产组结构时，不修改name
        asset.setAssetName(null);
        return asset;
    }
}
